// 控制应用生命周期和创建原生浏览器窗口的模组
const { BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const NODE_ENV = process.env.NODE_ENV;
console.log("ENV:", NODE_ENV);

// 登录窗口
const SettingWindow = () => {
  // 打开开发工具
  let width = 515,
    height = 460;
  // if (NODE_ENV === "development") {
  //   width = 515 + 660;
  //   console.log("开发环境");
  // }
  // 创建浏览器窗口
  const settingWindow = new BrowserWindow({
    width: width,
    height: height,
    icon: path.join(__dirname, "./../public/icon.png"),
    webPreferences: {
      sandbox: false,
      preload: path.join(__dirname, "preload.js"),
    },
  });
  settingWindow.setMenuBarVisibility(false);
  // 加载 index.html
  // mainWindow.loadFile('dist/index.html') 将该行改为下面这一行，加载url
  main_url =
    NODE_ENV === "development"
      ? "http://localhost:5173/"
      : `file://${path.join(__dirname, "../dist/index.html")}`;
  settingWindow.loadURL(main_url + "#/setting");
  // 打开开发工具
  if (NODE_ENV === "development") {
    settingWindow.webContents.openDevTools();
  }

  // 禁用开发工具
  settingWindow.webContents.on("before-input-event", (event, input) => {
    if (
      input.key === "F12" ||
      (input.control && input.shift && input.key === "I")
    ) {
      event.preventDefault(); // 禁用键盘快捷键打开开发者工具
    }
  });

  return settingWindow;
};

module.exports = SettingWindow;
